<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始时间：">
              <el-date-picker
                v-model="form.startDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间：">
              <el-date-picker
                v-model="form.endDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="餐饮单位：">
              <el-input
                v-model="form.pointName"
                style="width: 180px"
              ></el-input>
            </el-form-item>
            <!-- <el-form-item label="签批状态：">
              <el-select
                v-model="form.order"
                placeholder="请选择"
                style="width: 180px"
              >
                <el-option
                  v-for="item in select.OrderType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item> -->
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getTableData"
              >查 询</el-button
            >
            <!-- <el-button size="mini" type="success" @click="showTableDataAlarm"
              >逾期报警</el-button
            > -->
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
    >
      <el-table-column
        prop="餐饮单位"
        label="餐饮单位名称"
        align="center"
      ></el-table-column>
      <!-- <el-table-column
        prop="最早收运时间"
        label="最早收运时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="最晚结束时间"
        label="最晚结束时间"
        align="center"
      ></el-table-column> -->
      <!-- <el-table-column
        prop="垃圾类型"
        label="垃圾类型"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="垃圾桶类型"
        label="垃圾桶类型"
        :formatter="formatterBucketType"
      ></el-table-column>
      <el-table-column prop="预估桶数" label="预估桶数"></el-table-column> -->
      <el-table-column
        prop="预收运日期"
        label="预收运日期"
      ></el-table-column>
      <el-table-column prop="申请时间" label="申请时间"></el-table-column>
      <el-table-column prop="审核状态" label="审核状态"></el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button
            type="text"
            v-if="scope.row.审核状态 === '待审核'"
            @click="handleSign(scope.$index, scope.row)"
            >审核</el-button
          >
          <el-button
            type="text"
            v-if="scope.row.审核状态 === '待审核'"
            @click="handleShowReject(scope.$index, scope.row)"
            >驳回</el-button
          >
          <el-button
            type="text"
            v-if="scope.row.审核状态 != '待审核'"
            @click="handleShowOrderDetail(scope.$index, scope.row)"
            >审核信息</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
    <!-- 逾期报警列表 -->
    <el-dialog title="逾期未申请收运商户信息" :visible.sync="showAlarm" width="50%">
      <el-table :data="tableDataAlarm">
        <el-table-column prop="点位名称" label="餐饮单位名称"></el-table-column>
        <el-table-column prop="签批时间" label="签批时间"></el-table-column>
        <el-table-column prop="联系人" label="联系人"></el-table-column>
        <el-table-column prop="联系电话" label="联系电话"></el-table-column>
      </el-table>
    </el-dialog>
    <!-- 驳回申请窗口 -->
    <el-dialog title="驳回信息" :visible.sync="showReject" width="50%">
      <el-form class="flex" ref="formRow" :model="formRow" label-width="120px">
        <el-form-item label="餐饮单位名称："
          >{{ this.formRow.餐饮单位 }}
        </el-form-item>
        <el-form-item label="驳回理由：">
          <el-input
            type="textarea"
            v-model="formRow.reason"
            placeholder="请输入"
            class="handle-input mr10"
            style="width: 37.5vw; border: 1px solid #a4aca7"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showReject = false">取 消</el-button>
        <el-button type="primary" @click="rejectCollectionApply()"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 审核详情窗口 -->
    <el-dialog title="审核详情" :visible.sync="showOrderDetail" width="50%">
      <el-form class="flex" ref="formRow" :model="formRow" label-width="120px">
        <el-form-item label="餐饮单位名称："
          >{{ this.formRow.餐饮单位 }}
        </el-form-item>
        <el-form-item label="审核状态："
          >{{ this.formRow.审核状态 }}
        </el-form-item>
        <el-form-item label="审核时间："
          >{{ this.formRow.审核时间 }}
        </el-form-item>
        </el-form>
        <el-form class="flex" ref="formRow" :model="formRow" label-width="120px">
        <el-form-item label="驳回理由：" v-if="this.formRow.审核状态 === '审核未通过'"
          >{{ this.formRow.驳回理由 }}
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import '../../assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      tableData: [],
      tableDataAlarm: [],
      form: {
        startDate: formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24 * 30), 'yyyy-MM-dd'),
        endDate: formatDate(new Date(new Date().getTime() + 3600 * 1000 * 24), 'yyyy-MM-dd'),
        pointName: '',
        order: '-2',
      },
      formRow: {},
      select: {
        OrderType: [{
          value: '-2',
          label: '全部'
        }, {
          value: '0',
          label: '待审核'
        }, {
          value: '-1',
          label: '审核未通过'
          }, {
            value: '1',
            label: '审核通过'
        }],
      },
      showOrderDetail: false,
      showReject: false,
      showAlarm: false,
    }
  },
  mounted () {
    this.getTableData();
  },
  methods: {
    async updateApplyStatus (pointID) {
      var url = 'Sign/UpdataPlaceApplyIsorder?POINT_ID=' + pointID
      const { data } = await this.$Http.get(url)
      if (data.IsSucess) {
        this.$message.success('申请审核成功')
        this.getTableData()
      } else {
        this.$message.error('审核失败，请重新审核')
      }
    },
    async rejectCollectionApply () {
      var url = 'Sign/RejectCollectionApply?POINT_ID=' + this.formRow.POINT_ID + '&REASON=' + this.formRow.reason
      const { data } = await this.$Http.get(url)
      if (data.IsSucess) {
        this.$message.success('驳回审核成功')
        this.showReject = false;
        this.getTableData()
      } else {
        this.$message.error('驳回失败，请重新驳回')
      }
    },
    async getTableData () {
      var url = 'VehicleOil/GetPointApplyInfo?Type=2&ClientNo=001&Name=' + this.form.pointName
        + '&StartDate=' + this.form.startDate + '&EndDate=' + this.form.endDate
      const { data } = await this.$Http.get(url)
      this.tableData = data
    },
    async getTableDataAlarm () {
      var url = 'Sign/GetPointCollectionAlarmInfo?ClientNo=' + localStorage.getItem('CLIENT_NO')
      const { data } = await this.$Http.get(url)
      this.tableDataAlarm = data
    },
    showTableDataAlarm () {
      this.getTableDataAlarm();
      this.showAlarm = true;
    },
    // 详情
    handleShowReject (index, row) {
      this.formRow = Object.assign({}, row);
      this.showReject = true;
    },
    handleShowOrderDetail (index, row) {
      this.formRow = Object.assign({}, row);
      this.showOrderDetail = true;
    },
    // 签批
    handleSign (index, row) {
      this.$confirm('确认同意此申请？', '提示', {
        confirmButtonText: '同意',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.updateApplyStatus(row.POINT_ID)
      }).catch(() => {
      });
    },
    formatterBucketType (row, column, cellValue, index) {
      switch (cellValue) {
        case '1':
          return '120L';
        case '2':
          return '240L';
        case '3':
          return '铁桶';
        default:
          break;
      }
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
    },
    handleSizeChange (size) {
      this.pageSize = size;
      this.currentPage = 1;
    },
  }
}
</script>
